<template>
  <ContentWrap title="我的待办">
    <Search
      ref="search"
      :schema="schema"
      :model="queryParam"
      :is-col="false"
      layout="inline"
      :showSearch="true"
      button-position="left"
      :search-loading="loading"
      :reset-loading="loading"
      @search="handleSearch"
      @reset="handleSearch"
    />
    <el-divider />
    <userMsgList :query="query" />
  </ContentWrap>
</template>

<script>
import userMsgList from '@/components/msg/userMsgList.vue'
import { Search } from '@/components/Search'
export default {
  components: {
    Search,
    userMsgList
  },
  data() {
    return {
      loading: false,
      queryParam: {
        QueryKey: null,
        SearchType: 0,
        Time: null
      },
      schema: [
        {
          field: 'QueryKey',
          label: '待办标题',
          component: 'Input',
          componentProps: {
            placeholder: '待办标题'
          }
        },
        {
          field: 'SearchType',
          component: 'RadioButton',
          componentProps: {
            options: [
              { value: 0, label: '全部' },
              { value: 1, label: '已超时' },
              { value: 2, label: '催办' },
              { value: 3, label: '重要' },
              { value: 4, label: '优先处理' },
              { value: 6, label: '退回的' },
              { value: 7, label: '被打回修改' }
            ]
          }
        },
        {
          field: 'Time',
          label: '时段',
          component: 'DatePicker',
          componentProps: {
            type: 'daterange',
            format: 'YYYY-MM-DD',
            valueFormat: 'YYYY-MM-DD',
            startPlaceholder: '开始日期',
            endPlaceholder: '截止日期',
            rangeSeparator: '至',
            clearable: true
          }
        }
      ],
      query: {
        QueryKey: null,
        AppId: null,
        Priority: null,
        MsgClassify: '001',
        MsgType: 1,
        MsgStatus: 1,
        IsRead: null,
        IsTimeOut: null,
        Tag: null,
        Begin: null,
        End: null
      }
    }
  },
  computed: {},
  mounted() {},
  methods: {
    handleSearch(data) {
      this.loading = true
      this.query.QueryKey = data.QueryKey
      if (data.SearchType === 0) {
        this.query.IsTimeOut = null
        this.query.Tag = null
        this.query.Priority = null
      } else if (data.SearchType === 1) {
        this.query.IsTimeOut = true
        this.query.Tag = null
        this.query.Priority = null
      } else if (data.SearchType === 2) {
        this.query.IsTimeOut = null
        this.query.Tag = null
        this.query.Priority = [4]
      } else if (data.SearchType === 3) {
        this.query.IsTimeOut = null
        this.query.Tag = null
        this.query.Priority = [3]
      } else if (data.SearchType === 4) {
        this.query.IsTimeOut = null
        this.query.Tag = null
        this.query.Priority = [2]
      } else if (data.SearchType === 6) {
        this.query.IsTimeOut = null
        this.query.Tag = '002'
        this.query.Priority = null
      } else if (data.SearchType === 7) {
        this.query.IsTimeOut = null
        this.query.Tag = '003'
        this.query.Priority = null
      }
      if (data.Time && data.Time.length > 0) {
        this.query.Begin = data.Time[0]
        this.query.End = data.Time[1]
      } else {
        this.query.Begin = null
        this.query.End = null
      }
      this.loading = false
    }
  }
}
</script>
